package com.txf.simple.test.sms;

import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;

import com.txf.simple.tools.Logger;
/**
 * 联系人助手
 * */
public class ContactsHelper {
    private void getContactsAsync(Context context) {
        MyQueryHandler qh = new MyQueryHandler(context.getContentResolver());
        qh.startQuery(0, null, ContactsContract.Contacts.CONTENT_URI,
                null,
                null,
                null,
                null);
    }
    class MyQueryHandler extends AsyncQueryHandler {
        public MyQueryHandler(ContentResolver cr) {
            super(cr);
        }
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            super.onQueryComplete(token, cookie, cursor);
            while (cursor.moveToNext()) {
                Logger.i("id : "+cursor.getString(
                        cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID)));
                Logger.i("DISPLAY_NAME : "+cursor.getString(
                        cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
            }
            cursor.close();
        }
    }
}
